﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace MyZip
{
    class Consts{
        #region CONSTS

        // Byte Max
        public static int ByteValue = 256;
        // 文件最大长度
        public static int MaxFileLen = ByteValue * ByteValue * ByteValue * ByteValue;
        // 最大前移搜索长度
        public static int MaxLookAheadLen = ByteValue * ByteValue;
        // 最大重复串长度
        public static int MaxDupLen = ByteValue;
        // 文件头长度最大数值的位数
        public static int MaxHeadLengthDigi = 4;
        //字典的最大长度
        public const int DicLength = 250; //8 bits
        //字典存储所占位数
        public const int DicBits = 8;
        //缓冲区的最大长度
        public const int BufferLength = 60;//6 bits
        //缓冲区存储所占位数
        public const int BufferBits = 6;
        //模糊纠正值存储所占位数
        public const int DifBits = 4;

        #endregion
    }

    class ZipFile{
        string head{set;get;}
        Int32 headLength{set;get;}
        string body{set;get;}

        #region construcor
        public ZipFile(string content){
            for (int i = Consts.MaxHeadLengthDigi - 1; i >= 0; i--)
            {
                headLength += content[i] - '\0';
                headLength *= Consts.ByteValue;
                head = content.Substring(4, headLength - 4);
                body = content.Substring(headLength, content.Length - headLength);
            }
        }
        #endregion

    }

    class Engine
    {



#region UTILITY
        public string GetZippedFile(string content)
        {
            // File Head, repeatition infomation
            string head = "";
            // File Body, non-repeatition infomation
            string body = "";

            // File Head's head, shows the length of File Head
            string headHead = "";
            int headLen = head.Length;
            for (int i = 0; i < 4; i++)
            {
                
                headHead = headHead + (char)headLen % 128;
                headLen /= Consts.ByteValue;
            }
            return  headHead + head + body;
        }

        public string GetUnzippedFile(string content)
        {

            int headLen = 0;
            for (int i = 0; i < 4; i++)
            {
                headLen += content[3 - i];
                headLen *= Consts.ByteValue;
            }

            string ans = "";
            return ans;
        }
#endregion

#region FILE
        void Save(string filename, string content)
        {
        }
        void OpenZip(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            StreamReader rd = new StreamReader(fs);

            

        }
        string OpenFile(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            StreamReader rd = new StreamReader(fs);

            string ans = rd.ReadToEnd();

            rd.Close();
            fs.Close();

            return ans;
        }

#endregion
        
    }
}
